home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: const char??
- Date: 20 Feb 1996 16:55:38 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb20095538@qcd.lanl.gov>
- References: <31287436.1235873@news.inforamp.net> <4gb7u8$p5o@sun001.spd.dsccc.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: jmccarty@spd.dsccc.com's message of 20 Feb 1996 01:25:28 GMT
-
- In article <4gb7u8$p5o@sun001.spd.dsccc.com> jmccarty@spd.dsccc.com
- (Mike McCarty) writes:
- <snip>
- "const" means that the code is not permitted to change the object at run
- time (after perhaps an initial assignment).
-
- Almost, not quite though.
-
- const is an attribute of the type of an lvalue: When an lvalue with
- attribute const is used, it means that the code will not change the
- object using _that_ lvalue.
-
- The difference is crucial to understanding function prototypes: when
- we say that a function is declared `void f(const char *x)', we mean
- that the function f will not change the object through the lvalue
- `*x'. The same function may access a global `char y', and it might
- change y if it feels like, and if you had called f(&y), you can see
- that *x also got changed by this action!
-
- (There is a related issue that the function may also change *x by
- using the lvalue *(char*)x. That, and similar tricks, are so bad
- programming practices, that I won't even comment on them!)
-
- An object _defined_ a (i.e. an object whose storage was allocated by a
- declaration specifying) const, cannot be portably changed by the
- program. A compiler can assume it's value won't change unless it is
- also volatile: in which case, even though the program cannot write to
- it, the compiler has to assume that its value can change due to unkwon
- reasons.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-